"use strict";
cc._RF.push(module, 'bacf6Hzz4hB0KA8IcLnxXk2', 'PromoWall');
// scripts/PromoWall.js

"use strict";

var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
  value: !0
});

var o = e("PromoNodeArrItem"),
    i = cc._decorator,
    a = i.ccclass,
    r = i.property,
    s = function (e) {
  __extends(t, e);

  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.mDatas = null;
    t.itemList = [];
    t.prefab = null;
    t.layout = null;
    t.offsetWidth = 20;
    t.offsetHeight = 20;
    t.moveSpeed = 80;
    return t;
  }

  t.prototype.onLoad = function () {
    SDK.Base.Event.on("getData", this.initData, this);
    this.initData();
  };

  t.prototype.onDestroy = function () {
    SDK.Base.Event.off("getData", this.initData, this);
  };

  t.prototype.initData = function () {
    if (SDK.Mgr.Inst.hasPromoData && (SDK.Mgr.Inst.curChannel != SDK.Define.Channel.oppo || SDK.Mgr.Inst.isAdOpen)) {
      this.node.active = !0;
      this.mDatas = Config.Base.promoData;
      this.setData();
    } else this.node.active = !1;
  };

  t.prototype.setData = function () {
    var e = this.mDatas.content.length;
    if (e > 0) for (var t = 0; t < 3; t++) {
      this.mDatas.content.sort(function () {
        return Math.random() - .5;
      });

      for (var n = 0; n < e; n++) {
        var i = cc.instantiate(this.prefab);
        i.parent = this.layout;
        i.active = !0;
        var a = i.getComponent(o["default"]);

        if (null != a) {
          null == this.itemList[t] && (this.itemList[t] = []);
          this.itemList[t].push(a);
        }

        a.setData(this.mDatas.content[n]);
        var r = ((1 - e) / 2 + n + t % 2 / 2) * (i.width + this.offsetWidth),
            s = (1 - t) * (i.height + this.offsetHeight);
        i.setPosition(r, s);
      }
    }
  };

  t.prototype.update = function (e) {
    for (var t = this.mDatas.content.length, n = 0; n < 3; n++) {
      for (var o = 0; o < t; o++) {
        this.itemList[n][o].pNode.setPosition(this.itemList[n][o].pNode.position.x - e * this.moveSpeed, this.itemList[n][o].pNode.position.y);

        if (this.itemList[n][o].pNode.position.x < -t / 2 * (this.prefab.width + this.offsetWidth)) {
          var i = this.itemList[n][o].pNode.position.x + t * (this.prefab.width + this.offsetWidth);
          this.itemList[n][o].pNode.setPosition(i, this.itemList[n][o].pNode.y);
        }
      }
    }
  };

  __decorate([r(cc.Node)], t.prototype, "prefab", void 0);

  __decorate([r(cc.Node)], t.prototype, "layout", void 0);

  __decorate([r(cc.Float)], t.prototype, "offsetWidth", void 0);

  __decorate([r(cc.Float)], t.prototype, "offsetHeight", void 0);

  __decorate([r(cc.Float)], t.prototype, "moveSpeed", void 0);

  return __decorate([a], t);
}(cc.Component);

n["default"] = s;

cc._RF.pop();